******************************************************;
*This do file creates baseline controls from the 1990 Census
******************************************************;

capture clear
clear matrix
clear mata
capture macro drop _all
set more off
capture log close

#delimit ;

***SET DIRECTORY STRUCTURE***;
global data 
global data_save 


******************************************************;
use "${data}Census1990_Form3.dta", clear;

******************************************************;
*FIX GEOGRAPHIC DEFINITIONS TO BE CONSISTENT WITH CHED/CFO;
*Move Babak and Kaputian to Island Garden City of Samal;
replace mun="17" if prv=="23"&mun=="02";
replace mun="17" if prv=="23"&mun=="06";

*Move all of Manila into one province;
replace prv="39" if prv=="76"|prv=="74"|prv=="75";

*Create Biliran from Leyte;
replace prv="78" if prv=="37"&(mun=="04"|mun=="09"|mun=="11"|mun=="12"|mun=="16"|mun=="27"|mun=="32"|mun=="37");

*Create Guimaras from Iloilo (30);
replace prv="79" if prv=="30"&(mun=="11"|mun=="24"|mun=="33");


*******************************************************************************;
*Employment Variables;
rename kind_business indgen;

*25_64;
gen d6_nm_epop_2564=0 if age>=25&age<=64&oversea!=1;
replace d6_nm_epop_2564=1 if age>=25&age<=64&usual_occ!=.&oversea!=1&usual_occ!=910&usual_occ!=920;
replace d6_nm_epop_2564=0 if age>=25&age<=64&usual_occ>=210&usual_occ<=232&oversea!=1;

*FEMALE;
gen d6_nm_f_epop_2564=0 if age>=25&age<=64&sex==2&oversea!=1;
replace d6_nm_f_epop_2564=1 if age>=25&age<=64&sex==2&usual_occ!=.&oversea!=1&usual_occ!=910&usual_occ!=920;
replace d6_nm_f_epop_2564=0 if age>=25&age<=64&sex==2&usual_occ>=210&usual_occ<=232&oversea!=1;

*MALE;
gen d6_nm_m_epop_2564=0 if age>=25&age<=64&sex==1&oversea!=1;
replace d6_nm_m_epop_2564=1 if age>=25&age<=64&sex==1&usual_occ!=.&oversea!=1&usual_occ!=910&usual_occ!=920;
replace d6_nm_m_epop_2564=0 if age>=25&age<=64&sex==1&usual_occ>=210&usual_occ<=232&oversea!=1;

*Urban/rural status;
gen _urban=0;
replace _urban=1 if urban==1;

*Female;
gen _female=0;
replace _female=1 if sex==2;

*Years of Schooling;

tostring educ, replace;
replace educ=substr(educ, 1, 2);
rename educ p22_education;
destring p22_education, replace;

	*Years of schooling, by age;
	gen yrschl=0 if p22_education==0|p22_education==10;
	replace yrschl=1 if p22_education==11;
	replace yrschl=2 if p22_education==12;
	replace yrschl=3 if p22_education==13;
	replace yrschl=4 if p22_education==14;
	replace yrschl=5 if p22_education==15;
	replace yrschl=6 if p22_education==16;
	replace yrschl=7 if p22_education==21;
	replace yrschl=8 if p22_education==22;
	replace yrschl=9 if p22_education==23;
	replace yrschl=10 if p22_education==24;
	replace yrschl=11 if p22_education==31|p22_education==30;
	replace yrschl=12 if p22_education==32|(p22_education>=50&p22_education<=59);
	replace yrschl=13 if p22_education==33;
	replace yrschl=14 if (p22_education==34|p22_education==35|p22_education>=60)&p22_education!=98&p22_education!=99&p22_education!=.;
	
	gen _yrschl_2564_90=yrschl if age>=25&age<=64;
	
***************************;
*Collapse to province averages;
collapse (mean) __urban age _female _yrschl* d6* (sum) indicator* [pweight=pop_wgt], by(prv);

	
gen year=1990;

ren d6_nm_f_epop_2564 emp_f_2564_90;
ren d6_nm_m_epop_2564 emp_m_2564_90;
ren d6_nm_epop_2564 emp_2564_90;
ren _urban urban_90;
ren age age_90;
ren _female female_90;

keep *90 prv;

gen year=1990;

save "${data_save}census_controls_90_v2.dta", replace;


